package com.community.owner.controller;

import com.community.common.core.controller.BaseController;
import com.community.common.core.page.TableDataInfo;
import com.community.owner.domain.OwnerVehicleRecord;
import com.community.owner.domain.enums.SmartCode;
import com.community.owner.service.OwnerVehicleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/vehicleRecord")
public class OwnerVehicleRecordController extends BaseController {

    @Autowired
    private OwnerVehicleRecordService vehicleRecordService;


    @GetMapping("/selectAllVehicleRecords")
    public TableDataInfo selectAllVehicleRecords(OwnerVehicleRecord ownerVehicleRecord) {
        try {
            TableDataInfo result = vehicleRecordService.selectAllVehicleRecordsWithPage(ownerVehicleRecord);
            // 统一设置成功消息
            result.setMsg(SmartCode.Vehicle_Record_Success.getMsg());
            return result;
        } catch (Exception e) {
            logger.error("车辆记录失败详细错误:", e);
            TableDataInfo errorResult = getDataTable(new ArrayList<>());
            errorResult.setMsg(SmartCode.Vehicle_Record_Fail.getMsg()); // 设置失败消息
            return errorResult;
        }
    }
}
